//
//  MyComments.swift
//  newsApp
//
//  Created by Tirel on 2020/5/13.
//  Copyright © 2020 Doo Psyist. All rights reserved.
//

import Foundation

import SwiftUI
struct StreetinMyComments: Identifiable { //comments list
    var id = UUID()
    var comment: String
    var newtitle: String
}
struct StreetRowinMyComments: View {
    var street1: StreetinMyComments

    var body: some View {
        VStack(alignment: .leading) {
            Text(street1.newtitle)
                .font(.system(size: 20, design: .rounded))
                .bold()
                .foregroundColor(.orange)
            HStack {
                Image(systemName: "person.crop.square.fill")
                    .foregroundColor(.orange)
                    .imageScale(.large)

                Text("dukalee@foxmail.com")
                    .font(.headline)
            }

            HStack {
                Image(systemName: "pencil.and.ellipsis.rectangle")
                    .foregroundColor(.orange)
                    .imageScale(.large)

                Text(street1.comment)
                    .font(.subheadline)
            }

        }
    }
}

struct MyComments: View {
    @State var myCommentArray: Array<String> = []
    var body: some View {
        VStack(alignment: .leading) {
            Text("MyComments")
                .font(.system(size: 50, design: .rounded))
                .foregroundColor(Color.orange)
                .bold()
                .shadow(radius: 1)
            List(fetchComments()) { street in
                StreetRowinMyComments(street1: street)
            }
        }.padding(.bottom, 20)

    }
}
func fetchComments() -> Array<StreetinMyComments> {
    var res = Array<StreetinMyComments>()
    for tmp in networkJson {
        if !findNewsbyId(tmp.id)[0].comment!.isEmpty {
            for comment in loadComment(id: tmp.id) {
                res.append(StreetinMyComments(comment: comment, newtitle: tmp.title))
            }

        }
    }
    return res
}

struct MyComments_Previews: PreviewProvider {
    static var previews: some View {
        MyComments()
    }
}
